package com.accp.crm.service;

import java.util.List;

import org.hibernate.SessionFactory;

import com.accp.crm.dao.CommonDAO;
import com.accp.crm.entity.CstCustomer;
import com.accp.crm.entity.PageBean;

public class CstCustomerService implements ICstCustomerService {
	
	private CommonDAO<CstCustomer> custdao;
	
	public void setSessionFactory(SessionFactory sessionFactory){
		custdao=new CommonDAO<CstCustomer>(sessionFactory,CstCustomer.class);
	}

	@Override
	public List findAll() {
		List list = this.custdao.findAll();
		return list;
	}

	@Override
	public PageBean findByStatus(int pageNo,String no,String msgname) {
		String hql="from CstCustomer c where 1=1 ";
		if (no!=null ){
			hql += " and c.custNo like '%"
					+no+"%' ";
		}
		
		if (msgname!=null){
			hql += " and c.custManagerName like'%"
				+msgname+"%' ";
		}
		return this.custdao.findByPage(hql,pageNo, 10);
	}

	@Override
	public void delete(int id) {
		CstCustomer cust = this.custdao.findById(id);
		
		this.custdao.delete(cust);
		
	}

	@Override
	public void update(CstCustomer cust) {
		this.custdao.update(cust);
		
	}

	@Override
	public void add(CstCustomer cust) {
		this.custdao.save(cust);
	}

	@Override
	public List findByCount() {
		String hql="select from CstCustomer where custLeve=3";
		return null;
	}
	@Override
	public CstCustomer findById(String custNo) {
		String hql = "from CstCustomer c where c.custNo=? ";
		List list=this.custdao.findByHQL(hql, custNo);
		return (CstCustomer) list.get(0);
	}

	@Override
	public List findLinkman(String custNo) {
		String hql = "from CstLinkman c where c.cstCustomer=? ";
		return this.custdao.findByHQL(hql, custNo);
	}

	@Override
	public List findRegister(String custNo) {
		String hql = "from CstActivity c where c.cstCustomer=?";
		return this.custdao.findByHQL(hql, custNo);
	}

	

}
